import axios from 'axios'
import request from './request'




// 测试
export function getItem() {
  return request.get('/playlist/highquality/tags'

  )
}

// 得到二维码key
export function getkey() {
  return request.get(`/login/qr/key`,
    { timerstamp: new Date().getTime() })
}

// 二维码生成接口
export function getCode(key) {
  return request.get(`/login/qr/create`,
    {
      params: {
        timerstamp: new Date().getTime(),
        qrimg: true,
        key
      }
    }

  )
}
// 二维码检测扫码状态

export function getCheck(key) {
  return request.get(`/login/qr/check`,
    {
      params: {
        timerstamp: new Date().getTime(),
        key
      }
    }

  )
}

// 刷新登录
export function loginRefresh() {
  return request.get(`/login/refresh`)

}

// 手机登录
export function loginByPhone(ruleForm) {
  return request.get(`/login/cellphone`,
    {
      params: {
        phone: ruleForm.phone,
        password: ruleForm.password
      }
    }
  )

}
// 退出登录
export function logout() {
  return request.get(`/logout`)

}

// 搜索建议
export function searchSuggest(keywords) {
  return request.get(`/search/suggest?keywords=${keywords}`)
}

// 获取登录状态
export function loginStatus() {
  return request.get(`/login/status`)

}
// 获取用户详情

export function userDetail(uid) {
  return request.get(`/user/detail`,
    { params: { uid } }
  )

}

// 获取轮播图
export function getSwiper() {
  return request.get(`/banner`)
}

// 获取推荐歌单热门
export function getRecommendSongList(limit) {
  return request.get(`/personalized`,
    { params: { limit } }
  )
}

// 获取新碟上架热门
export function getNewAlbum(limit) {
  return request.get(`/top/album`,
    {
      params: {
        limit,


      }
    }
  )
}


// 获取所有榜单
export function getTopList() {
  return request.get(`/toplist`)
}

// 获取推荐页排行榜  歌单详情
export function getrecommendTop(id) {
  return request.get(`/playlist/detail`,
    {
      params: {
        id,
        timerstamp: new Date().getTime()
      }
    }
  )
}
// 获取歌曲URL
export function getSongURL(id) {
  return request.get(`/song/url`, {
    params: {
      id
    }
  })
}

// 获取热门歌手
export function getHotSinger() {
  return request.get(`/toplist/artist`)
}

// 获取热门主播
export function getHotAnchor(limit) {
  return request.get(`/dj/toplist/popular`, {
    params: {
      limit,
      timerstamp: new Date().getTime()
    }
  })
}

// 获取全部热门歌单
export function getPlaylist(params) {
  return request.get(`/top/playlist`, {
    params: {
      cat: params.cat,
      limit: params.limit,
      offset: params.offset
    }
  }
  )
}

// 获取歌单分类列表
export function getCategory() {
  return request.get(`/playlist/catlist`)
}


// 获取歌单所有歌曲
export function getAllSong(id) {
  return request.get(`/playlist/track/all`, {
    params: { id }
  })
}

// 获取歌单评论

export function getAllComment(id, commentInfo) {
  return request.get(`/comment/playlist`, {
    params: {
      id: id,
      limit: commentInfo.limit,
      offset: commentInfo.offset,
      before: commentInfo.before
    }
  })
}

// 发送评论
export function comment(t, type, id, content, commentId) {
  return request.post(`/comment?cookie=${window.sessionStorage.getItem('cookie')}&t=${t}&type=${type}&id=${+id}&content=${content}&commentId=${commentId}`
    //  {
    //   data: {
    //     // 1 发送, 2 回复
    //     t,
    //     // 数字,资源类型,对应歌曲,mv,专辑,歌单,电台,视频对应以下类型
    //     type,
    //     // 对应资源 id
    //     id: +id,
    //     // 要发送的内容
    //     content,
    //     // 回复的评论 id (回复评论时必填)
    //     commentId: '',
    //     timerstamp: new Date().getTime(),

    //   }
    // }
  )
}

// 给评论点赞
export function likeComment(type, item) {

  return request.post(`/comment/like?cookie=${window.sessionStorage.getItem('cookie')}`, {
    data: {
      id: item.id,
      cid: item.commentId,
      t: item.liked ? 0 : 1,
      type,
      timerstamp: new Date().getTime()
    }
  })
}
// 获取歌曲
export function getSongDeatil(ids) {
  return request.get(`/song/detail`, {
    params: {
      ids
    }
  })
}
// 获取歌曲歌词

export function getSongLyric(id) {
  return request.get(`/lyric`, {
    params: {
      id
    }
  })
}
// 获取歌曲评论
export function getSongComment(id, commentInfo) {
  return request.get(`/comment/music`, {
    params: {
      id: id,
      limit: commentInfo.limit,
      offset: commentInfo.offset,
      before: commentInfo.before
    }
  })
}
// 获取相似歌曲

export function getSimiSong(id) {
  return request.get(`/simi/song`, {
    params: {
      id
    }
  })
}

// 电台

// 获取电台分类
export function getDjCatelist() {
  return request.get(`/dj/catelist`)
}

// 获取电台推荐节目
export function getDjRecommend() {
  return request.get(`/program/recommend`)
}

// 获取节目排行榜

export function getDjTopList(limit) {
  return request.get(`/dj/program/toplist?limit=${limit}`)
}

// 获得电台推荐类型
export function getCategoryRecommend() {
  return request.get(`/dj/category/recommend`)
}

// 获取全部歌手
export function getAllArtist(initial, offset, limit) {
  return request.get(`/artist/list?type=-1&area=-1&initial=${initial}&offset=${offset}&limit=${limit}`)
}

// 获取全部新碟
export function getAllAlbum(albumInfo) {
  return request.get(`/album/new`, {
    params: {
      limit: albumInfo.limit,
      offset: albumInfo.offset,
      area: albumInfo.area
    }
  })
}

// 获取mv  url 
export function getMvUrl(id, r) {
  return request.get(`/mv/url?id=${id}`, {
    params: {
      r
    }
  })
}

// 获取mv 细节
export function getMvDetail(id) {
  return request.get(`/mv/detail?mvid=${id}`)
}

// 获取mv评论

export function getMvComment(id, mvInfo) {
  return request.get(`/comment/mv?id=${id}`, {
    params: {
      limit: mvInfo.limit,
      offset: mvInfo.offset,
      before: mvInfo.before
    }
  })
}

export function updateImg(formData) {
  // return request.post(`/avatar/upload?cookie=${window.sessionStorage.getItem('cookie')}&imgSize=180&imgX=0&imgY=0&timerstamp=${new Date().getTime()}`, {
  //   headers: {
  //     'Content-Type': 'multipart/form-data',
  //   },
  //   data: formData

  // }

  // )
  return axios({
    method: 'post',
    url: `/avatar/upload?cookie=${window.sessionStorage.getItem('cookie')}&imgSize=180&imgX=0&imgY=0&timerstamp=${new Date().getTime()}`,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
  })
}